﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace SPMigrationOracleUtility
{
    public partial class frm_Mapping : Form
    {
        Timer timer1 = new Timer();
        Map_Migration objImp = new Map_Migration();
        DataTable dtResults;
        DataTable dt;
        cls_mapping obj = new cls_mapping();
        Collect_Site obj1 = new Collect_Site();
        orcConnection objCon = new orcConnection();
        bool flag = false;
        bool flg;
        bool pnl3flag;
        bool flagMapInit;
        bool flagcgintabl;

        bool srctblchanged = false,desttblchanged=false;
        int ListSelectioncnt = 0;
        int Libraryselcount = 0;
        public string SiteUrl = Convert.ToString(SPMigrationOracleUtility.Appl.Default.SiteURL);


        private void frm_Mapping_Load(object sender, EventArgs e)
        {
            // set the panel style
            this.Height = 450;
            this.Width = 800;
            txtUrl.Text = SiteUrl;
            obj.Panel_Prop(pnlMappingname);
            obj.Panel_Prop(pnlDBList);
            obj.Panel_Prop(pnlURL);
            obj.Panel_Prop(pnlGrid);
            obj.Panel_Prop(pnlGridBind);
            obj.Panel_Prop(pnlIntegrate);
            txtUrl.Text = SiteUrl;
            obj.Lst_Tbl_Rec(rdBtnTables, btnDbForward, lstMapDBs, lstMapDB, flag);
            lblDisp.Text = "Oracle and SharePoint Mapping Step-1 - Create Mapping Name";
        }

        public frm_Mapping()
        {
            InitializeComponent();
        }

        private void txtMappingName_KeyDown(object sender, KeyEventArgs e)
        {
            if (Convert.ToInt32(e.KeyValue) == 13)
            {
                txtMappingDesc.Focus();
                btnNextPnl1.Enabled = true;
                
            }
            else
            {

            }
        }

        private void txtMappingDesc_KeyDown(object sender, KeyEventArgs e)
        {
                       
            btnNextPnl1.Enabled = true;
            if (Convert.ToInt32(e.KeyValue) == 13)
            {

                btnNextPnl1.Focus();
            }
            else
            {

            }
        }

        private void btnNextPnl1_Click(object sender, EventArgs e)
        {
            Pnl2_Transaction();
        }

        private void Pnl2_Transaction()
        {
            flag = false;
            lblDisp.Text = "Oracle and SharePoint Mapping Step-2 - Select Oracle Mapping List";
            pnlDBList.Visible = true;
            pnlMappingname.Visible = false;
            btnDbBackward.Enabled = false;
            btnDbForward.Enabled = true;

            if (rdBtnTables.Checked)
            {
                if (lstMapDB.Items.Count == 2 && flg == true)
                {
                    btnDbBackward.Enabled = true;
                    btnDbForward.Enabled = false;
                }
                else if (lstMapDB.Items.Count == 1 && flg == true)
                {
                    btnDbForward.Enabled = true;
                    btnDbBackward.Enabled = true;
                }
                else
                { }
            }
            else
            {
                if (lstMapDB.Items.Count == 1 && flg == true)
                {
                    btnDbBackward.Enabled = true;
                    btnDbForward.Enabled = false;
                }

                else
                { }
            }
        }
    
        private void txtMappingName_Enter(object sender, EventArgs e)
        {
            btnNextPnl1.Enabled = false;
        }

        private void txtMappingDesc_Enter(object sender, EventArgs e)
        {
            btnNextPnl1.Enabled = true;
        }
      
        private void rdBtnTables_Click(object sender, EventArgs e)
        {
            if (pnl3flag)
            {
                
            }
            else
            {
                btnDbBackward.Enabled = false;
                obj.Lst_Tbl_Rec(rdBtnTables, btnDbForward, lstMapDBs, lstMapDB, flag);
            }
         }

        private void rdBtnViews_Click(object sender, EventArgs e)
        {
            if (pnl3flag)
            {

            }
            else
            {
                btnDbBackward.Enabled = false;
                obj.Lst_View_Rec(rdBtnViews, btnDbForward, lstMapDBs, lstMapDB, flag);
            }
        }

        private void btnDbForward_Click(object sender, EventArgs e)
        {
            if (rdBtnTables.Checked)
            {
                obj.Btn_DbForward(rdBtnTables, lstMapDBs, lstMapDB, btnDbForward, btnDbBackward, btnNextPnl2);
            }
            else
            {
                obj.Btn_DbForward(rdBtnViews, lstMapDBs, lstMapDB, btnDbForward, btnDbBackward, btnNextPnl2);
            }
                   

        }

        private void btnDbBackward_Click(object sender, EventArgs e)
        {
            obj.Btn_DbBackward(lstMapDBs, lstMapDB, btnDbForward,btnDbBackward, btnNextPnl2);
        }
    
        private void btnPrevPnl2_Click(object sender, EventArgs e)
        {
            lblDisp.Text = "Oracle and SharePoint Mapping Step-1 - Create Mapping Name";
            flg = true;
            flag = true;
            pnlMappingname.Visible = true;
            btnNextPnl1.Enabled = true;
            btnPrevPnl2.Enabled = true;
            pnlDBList.Hide();
         }

        private void btnNextPnl2_Click(object sender, EventArgs e)
        {
            lblDisp.Text = "Oracle and SharePoint Mapping Step-3 - Select SharePoint Mapping List";
            pnl3flag = true;
            pnlDBList.Hide();
            pnlURL.Show();
        }

        private void btnCancelPnl1_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void btnCancelPnl2_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void txtMappingDesc_TabIndexChanged(object sender, EventArgs e)
        {
            btnNextPnl1.Enabled = true;
            btnNextPnl1.Focus();
        }

        private void txtMappingDesc_Leave(object sender, EventArgs e)
        {
            btnNextPnl1.Focus();
        }

        private void txtMappingName_Leave(object sender, EventArgs e)
        {
            if (txtMappingName.Text == "")
            {
                btnNextPnl1.Enabled = false;
            }
            else
            {
                btnNextPnl1.Enabled = true;
            }
          
        }

        private void btnCancelPnl3_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void btnPrevPnl3_Click(object sender, EventArgs e)
        {
                lblDisp.Text = "Oracle and SharePoint Mapping Step-2 - Select Oracle Mapping List";
                pnl3flag = false;
                pnlDBList.Show();
                pnlURL.Hide();
        }

        private void btnGo_Click(object sender, EventArgs e)
        {
            cmbSites.Items.Clear();  // 15feb2012

            obj1.GetSubSites(cmbSites, txtUrl.Text);
            // Bind sites and subsites from the corresponding URL and their List and Libraries
            if (cmbSites.Items.Count > 0)
            {
                cmbSites.SelectedIndex = 0;
            }
        }

        private void cmbSites_SelectedIndexChanged(object sender, EventArgs e)
        {
            ListItemPair oweb = (ListItemPair)cmbSites.SelectedItem;
            obj1.GetLists(lstLibList, cmbSites, oweb.URL);
            clr_MapList();
        }

        private void clr_MapList()
        {
            lstMapListLib.Items.Clear();
            ListSelectioncnt = 0;
            Libraryselcount = 0;
            Step4Enable();

            if (lstLibList.Items.Count > 0)
            {
                btnListLibAdd.Enabled = true;
            }
            else
            {
                btnListLibAdd.Enabled = false;
            }

        }

        private void btnNextPnl3_Click(object sender, EventArgs e)
        {
            Pnl4_Tranaction();
        }

        private void Pnl4_Tranaction()
        {
            // Set the Source Table Name,columns and their corresponding data types.
            // Set the Destination List Name,columns and their corresponding data types.
            ListItemPair li = (ListItemPair)cmbSites.SelectedItem;
            lblDestSiteName.Text = li.URL;

            lblDisp.Text = "Oracle and SharePoint Mapping Step-4 - Oracle-SharePoint - Mapping Process";
            pnlURL.Hide();
            pnlGrid.Show();

            if (flagMapInit)
            {
                Map_ck_TblView();
                Map_ck_LstLib();
                if (srctblchanged == true || desttblchanged == true)
                {
                    MappingInit();
                    dg1.DataSource = null;
                    AddTableColumn();
                    srctblchanged = false;
                    desttblchanged = false;
                    flagcgintabl = true;
                }
                else
                {
                    //flagcgintabl = false;
                }
            }
            else
            {
                AddTableColumn();
                MappingInit();
            }

            if (dg1.Rows.Count == 0) { btnNextPnl4.Enabled = false; } else { btnNextPnl4.Enabled = true; }
               
        }

        public void Map_ck_TblView()
            {
                foreach (string srctblName in lstMapDB.Items)
                {
                    if(!CmbSrcTableName.Items.Contains(srctblName ) )
                        srctblchanged = true;
                
                }


                if (lstMapDB.Items.Count != CmbSrcTableName.Items.Count)
                {
                    srctblchanged = true;
                }

            }

        public void Map_ck_LstLib()
        {
            try
            {
                foreach (ListItemPair srctblName in lstMapListLib.Items)
                {
                    if(!CmbDestListName.Items.Contains( srctblName))
                            srctblchanged = true;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            if (lstMapListLib.Items.Count != CmbDestListName.Items.Count)
            {
                desttblchanged = true;
            }

        }
        
        public void MappingInit()
        {
            CmbDestListName.Items.Clear();
            CmbSrcTableName.Items.Clear();

            CmbDestListName.DisplayMember = "Text";
            foreach (object obj in lstMapListLib.Items)
            {
                CmbDestListName.Items.Add(obj);
                
            }
            if (CmbDestListName.Items.Count > 0)
                CmbDestListName.SelectedIndex = 0;
            foreach (object obj in lstMapDB.Items)
            {
                CmbSrcTableName .Items.Add(obj);
            }
            if (CmbSrcTableName.Items.Count > 0)
                CmbSrcTableName.SelectedIndex = 0;
        }

        public void AddTableColumn()
        {
            dt = new DataTable();
            dt.Columns.Add("SourceTableName", typeof(string));
            dt.Columns.Add("SourceTableColumn", typeof(string));
            dt.Columns.Add("SourceColumnType", typeof(string));
            dt.Columns.Add("DestinationListName", typeof(string));
            dt.Columns.Add("DestinationListColumn", typeof(string));
            dt.Columns.Add("DestinationColumnType", typeof(string));
            dt.Columns.Add("DestinationListTemplate", typeof(string));
            dg1.DataSource = dt;
        }
        
        private void btnPrevPnl4_Click(object sender, EventArgs e)
        {
            flagMapInit = true;
            lblDisp.Text = "Oracle and SharePoint Mapping Step-3 - Select SharePoint Mapping List";
            pnlGrid.Hide();
            pnlURL.Show();
        }

        private void btnCancelPnl4_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void btnListLibAdd_Click(object sender, EventArgs e)
        {
            if (lstLibList.Text == "")
                MessageBox.Show("Please Select List / Library");
            else
                MoveData(lstLibList, lstMapListLib, 1);
      
        }

        public void Step4Enable()
        {
            if (ListSelectioncnt > 0 || Libraryselcount > 0)
            {
                btnNextPnl3.Enabled = true;
                btnListLibRem.Enabled = true;
            }
            else
            {
                btnListLibAdd.Enabled = true;
                btnNextPnl3.Enabled = false;
                btnListLibRem.Enabled = false;
            }
        }

        public void MoveData(ListBox objListsrc, ListBox objListDest, int val)
        {

            // Check and  count the List and Library to move the records from source SP list to destination SP list.
            bool adddata1 = false;
            string type1 = "";

            try
            {
                ListItemPair objList = (ListItemPair)objListsrc.SelectedItem;
                if (objList.ListTemplate == Microsoft.SharePoint.Client.BaseType.DocumentLibrary)
                {
                    Libraryselcount = Libraryselcount + val;
                }
                else
                {
                    ListSelectioncnt = ListSelectioncnt+val ;
                }

                if (ListSelectioncnt == 0 && Libraryselcount == 1)
                {
                    adddata1 = true;
                    btnListLibAdd.Enabled = true;

                }
                else if (ListSelectioncnt == 1 && Libraryselcount == 0)
                {

                    adddata1 = true;
                    btnListLibAdd.Enabled = true;

                }
                else if (ListSelectioncnt == 2 && Libraryselcount == 0)
                {
                    adddata1 = true;
                    btnListLibAdd.Enabled = false;

                }
                else if (ListSelectioncnt == 1 && Libraryselcount == 1)
                {
                    adddata1 = true;
                    btnListLibAdd.Enabled = false;
                }
                else if (ListSelectioncnt == 0 && Libraryselcount == 0)
                {
                    adddata1 = true;
                }
                else
                {
                    Libraryselcount = 1;
                     MessageBox.Show("Invalid Mapping.");
                }

                if (adddata1)
                {
                    objListDest.Items.Add(objList);
                    objListDest.DisplayMember = "Text";
                    int selectedIndex = Convert.ToInt32(objListsrc.SelectedIndex);
                    objListsrc.Items.RemoveAt(selectedIndex);
                }
            }
            catch (SystemException ex)
            {
                MessageBox.Show("Select the valid List or Library");
            }


            Step4Enable();
        }

        private void btnListLibRem_Click(object sender, EventArgs e)
        {
            MoveData(lstMapListLib, lstLibList, -1);
        }

        public enum ObjectState
        {
            Structure,
            Data
        }

        private void CmbSrcTableName_SelectedIndexChanged(object sender, EventArgs e)
        {
            CmbSrcFieldName.Items.Clear();
            obj.LoadObjectData("Data", CmbSrcTableName, CmbSrcFieldName);
        }

        private void CmbSrcFieldName_SelectedIndexChanged(object sender, EventArgs e)
        {
            obj.LoadObjectType("Data", CmbSrcFieldName, lblSrcFieldName);
        }

        private void CmbDestListName_SelectedIndexChanged(object sender, EventArgs e)
        {
            ListItemPair oweb = (ListItemPair)CmbDestListName.SelectedItem;
            obj1.GetListFields(CmbDestListName, CmbDestFieldName, oweb.URL);
         }

        private void CmbDestFieldName_SelectedIndexChanged(object sender, EventArgs e)
        {
            obj1.GetListFieldType(CmbDestFieldName, lblDestFieldName);
        }
       
        private void btnAddGrid_Click(object sender, EventArgs e)
        {
            // Add source and destination mapping records to the grid.
            bool exist = false;
            SourceFieldType objsrc = (SourceFieldType)CmbSrcFieldName.SelectedItem;
            ListItemPair dispName = (ListItemPair)CmbDestListName.SelectedItem;
            DestFieldType intName = (DestFieldType)CmbDestFieldName.SelectedItem;

            foreach (DataRow row in dt.Rows)
            {
                if (Convert.ToString(row["SourceTableName"]) == Convert.ToString(CmbSrcTableName.SelectedItem)
                    && Convert.ToString(row["SourceTableColumn"]) == Convert.ToString(objsrc.fieldName) 
                    && Convert.ToString(row["SourceColumnType"]) == Convert.ToString(lblSrcFieldName.Text) 
                    && Convert.ToString(row["DestinationListName"]) == Convert.ToString(dispName.Text) 
                    && Convert.ToString(row["DestinationListColumn"]) == Convert.ToString(intName.internalName) 
                    && Convert.ToString(row["DestinationColumnType"]) == Convert.ToString(lblDestFieldName.Text)
                    && Convert.ToString(row["DestinationListTemplate"]) == Convert.ToString(dispName.ListTemplate))
               
                {
                    MessageBox.Show("Duplicate Entry ! Same entry exists ","Duplication",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                    exist = true;
                }

                else if (Convert.ToString(row["DestinationListName"]) == Convert.ToString(dispName.Text) && Convert.ToString(row["DestinationListColumn"]) == Convert.ToString(intName.internalName))
                   
                {
                    MessageBox.Show("Cannot map Destination List Field twice" + System.Environment.NewLine + "'" + row["DestinationListColumn"] + "'  Field already mapped", "Mapping Exist Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    exist = true;
                }
            }

            if (!exist)
            {
                if (string.Equals(lblDestFieldName.Text, "File", StringComparison.CurrentCultureIgnoreCase))
                {
                    DialogResult result = MessageBox.Show("Could you please ensure Source Table field '" + objsrc.fieldName + "' consist URL(Document Path). Since you have selected Document Libray", "Document Library Verification", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                    if (result == DialogResult.OK)
                    {
                        dt.Rows.Add(CmbSrcTableName.SelectedItem, objsrc.fieldName, lblSrcFieldName.Text, dispName.Text, intName.internalName, lblDestFieldName.Text, Convert.ToString(dispName.ListTemplate));
                        dg1.DataSource = dt;
                    }
                }
                else
                {
                    dt.Rows.Add(CmbSrcTableName.SelectedItem, objsrc.fieldName, lblSrcFieldName.Text, dispName.Text, intName.internalName, lblDestFieldName.Text, Convert.ToString(dispName.ListTemplate));
                    dg1.DataSource = dt;
                }
            }
            if (dg1.Visible)
            {
                btnNextPnl4.Enabled = true;
            }
            

        }

        private void dg1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                if (dg1.Rows.Count > 0)
                {
                    contextMenuStrip1.Show(Cursor.Position);
                }
            }
        }

        private void deleteSelectedRowToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you want to Delete the Selected Row ?", "Row Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
            {
                dg1.Rows.Remove(dg1.CurrentRow);
            }
            if (dg1.Rows.Count == 0) { btnNextPnl4.Enabled = false; } else { btnNextPnl4.Enabled = true; }
        }

        private void btnNextPnl4_Click(object sender, EventArgs e)
        {
            // set which one is selected in the screen Allitems or Query
            // If Allitems is selected all records of Oracle table records are retrieved from DB
            // otherwise write the query. but be mind, the query field must contain selected mapping columns.
            OSP_MappingProcess();
        }
    
        private void OSP_MappingProcess()
        {
            lblDisp.Text = "Oracle and SharePoint Mapping Step-5 - Oracle-Data Access";
            pnlGridBind.Show();
            pnlGrid.Hide();
            if (rdBtnTables.Checked == true && obj.cnt == 1)
            {
                gvBind.DataSource = null;
                rdBtnAll.Enabled = true;
                rdBtnAll.Checked = true;
                rdBtnQuery.Enabled = false;
                txtQuery.Enabled = false;
                txtQuery.Text = "";
                btnExecute.Enabled = false;
                string strQry = "select * from " + CmbSrcTableName.Text;
                obj.LoadOrcData(strQry, gvBind);
            }
            else if (rdBtnTables.Checked == true && obj.cnt == 2)
            {
                if (flagcgintabl == false)
                {
                    txtQuery.Text = txtQuery.Text;
                    rdBtnAll.Enabled = false;
                    rdBtnAll.Checked = false;
                    rdBtnQuery.Enabled = true;
                    rdBtnQuery.Checked = true;
                    txtQuery.Enabled = true;
                    btnExecute.Enabled = true;
                }
                else
                {
                    txtQuery.Text = "";
                    gvBind.DataSource = null;
                    rdBtnAll.Enabled = false;
                    rdBtnAll.Checked = false;
                    rdBtnQuery.Enabled = true;
                    rdBtnQuery.Checked = true;
                    txtQuery.Enabled = true;
                    btnExecute.Enabled = true;
                    flagcgintabl = false;
                }

            }
            else
            {
                txtQuery.Text = "";
                gvBind.DataSource = null;
                rdBtnAll.Enabled = true;
                rdBtnAll.Checked = true;
                rdBtnQuery.Enabled = false;
                txtQuery.Enabled = false;
                btnExecute.Enabled = false;
                string strQry = "select * from " + CmbSrcTableName.Text;
                obj.LoadOrcData(strQry, gvBind);

            }

            if (gvBind.DataSource == null) { btnNextPnl5.Enabled = false; } else{ btnNextPnl5.Enabled = true; }
         }

        private void btnCancelPnl5_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void btnPrevPnl5_Click(object sender, EventArgs e)
        {
            lblDisp.Text = "Oracle and SharePoint Mapping Step-4 - Oracle-SharePoint - Mapping Process";
            pnlGrid.Show();
            pnlGridBind.Hide();
        }

        private void btnExecute_Click(object sender, EventArgs e)
        {
            // Load oracle data from the DB.
            Execute_Query();
            if (gvBind.DataSource == null) { btnNextPnl5.Enabled = false; } else { btnNextPnl5.Enabled = true; }
           
        }

        private void Execute_Query()
        {
            try
            {
                int cnt = 0;
                if (txtQuery.Text.Trim() != "")
                {
                    if (txtQuery.Text.Trim().ToUpper().Contains(" FROM "))
                    {
                       if (rdBtnTables.Checked && obj.cnt == 2)
                        {
                            string strCk = null;
                            string QRY = txtQuery.Text.ToUpper().Substring(txtQuery.Text.ToUpper().LastIndexOf(" FROM "));
                            string wHQRY = QRY.Substring(QRY.LastIndexOf(" FROM "), QRY.LastIndexOf(" WHERE ")).Replace(" FROM ", "");
                            string[] tbls = wHQRY.Split(',');
                                foreach (string tbl in tbls)
                                  {
                                      strCk = tbl.Trim();
                                      strCk = strCk.Split(' ')[0];
                                    {
                                        foreach (string li in lstMapDB.Items)
                                        {
                                            if (strCk == li)
                                            {
                                                cnt++;
                                            }

                                        }

                                    }
                                  }
                                if (cnt == 2)
                                {
                                    obj.LoadOrcData(txtQuery.Text, gvBind);
                                }
                                else
                                {
                                    gvBind.DataSource = null;
                                    MessageBox.Show("You cannot configure with other table or Invalid table name");
                                }
                        }
                        else
                        {
                            obj.LoadOrcData(txtQuery.Text, gvBind);
                         //view coding
                        }
                    }

                    else
                    {
                        obj.LoadOrcData(txtQuery.Text, gvBind);
                    }

                }
           
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message + System.Environment.NewLine + "Or" + System.Environment.NewLine + "Pls check your query");
                gvBind.DataSource = null;
            }
        
        }

        private void btnNextPnl5_Click(object sender, EventArgs e)
        {
            lblDisp.Text = "Oracle and SharePoint Mapping Step-6 - Oracle-To-SharePoint-Posting";
            pnlIntegrate.Show();
            pnlGridBind.Hide();
            Mapping_Integrate();
        }

        private void btnPrevPnl6_Click(object sender, EventArgs e)
        {
            lblDisp.Text = "Oracle and SharePoint Mapping Step-5 - Oracle-Data Access";
            pnlGridBind.Show();
            pnlIntegrate.Hide();
        }

        public void Mapping_Integrate()
        {
            lblMapName.Text = txtMappingName.Text.ToUpper();
            lblMapDesc.Text = txtMappingDesc.Text.ToUpper();

            lblSrcTblView.Text = "";
            foreach (string srctblName in lstMapDB.Items)
            {
                string s = srctblName.ToUpper();
                lblSrcTblView.Text = lblSrcTblView.Text + System.Environment.NewLine + s.ToString();
            }

            lblDestListLib.Text = "";
            foreach (ListItemPair destListName in lstMapListLib.Items)
            {
                string s = destListName.Text.ToUpper();
                lblDestListLib.Text = lblDestListLib.Text + System.Environment.NewLine + s.ToString();
            }
            
            
            lblMapRowCnt.Text = Convert.ToString(dg1.Rows.Count);
            lblSrcRecCnt.Text = Convert.ToString(gvBind.Rows.Count);
        }

        private void btnCancelPnl6_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {

            // To store the records in to ths Mapping List and Mapping column List
            if (rdBtnAll.Checked && rdBtnTables.Checked)
            {
                Mapping_List objMap = new Mapping_List(txtMappingName.Text, txtMappingDesc.Text, Convert.ToString(rdBtnAll.Checked), txtQuery.Text, "","");
                objMap.MapList(dt, lblDestSiteName.Text);
                MessageBox.Show("Mapping Created");
                this.Close();
            }
            else if (rdBtnQuery.Checked && obj.cnt==2)
            {
                Mapping_List objMap = new Mapping_List(txtMappingName.Text, txtMappingDesc.Text, Convert.ToString(rdBtnAll.Checked), txtQuery.Text, "","");
                objMap.MapList(dt, lblDestSiteName.Text);
                MessageBox.Show("Mapping Created");
                this.Close();
            }
            else
            {
                Mapping_List objMap = new Mapping_List(txtMappingName.Text, txtMappingDesc.Text, Convert.ToString(rdBtnAll.Checked), txtQuery.Text, CmbSrcTableName.Text,"");
                objMap.MapList(dt, lblDestSiteName.Text);
                MessageBox.Show("Mapping Created");
                this.Close();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void btnMigRun_Click(object sender, EventArgs e)
        {
           
        }

        private void btnMigcancel_Click(object sender, EventArgs e)
        {
            
        }

        private void txtMappingName_MouseMove(object sender, MouseEventArgs e)
        {
            if (txtMappingName.Text == "")
            {
                btnNextPnl1.Enabled = false;
            }
            else
            {
                btnNextPnl1.Enabled = true;
            }
        }

        private void pnlMappingname_MouseMove(object sender, MouseEventArgs e)
        {
            if (txtMappingName.Text == "")
            {
                btnNextPnl1.Enabled = false;
            }
            else
            {
                btnNextPnl1.Enabled = true;
            }
        }

    }
}


